package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.goods.ProductCategory;
import com.blog.service.ProductCategoryBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.http.HttpRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductCategoryBaseController
 * @Destription ProductCategory基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/productCategory")
public class ProductCategoryBaseController {
    @Autowired
    ProductCategoryBaseService productCategoryBaseService;
    @GetMapping("/selectAllProductCategory")
    public List<ProductCategory> selectAllProductCategory(){
        return productCategoryBaseService.selectAllProductCategory();
    }

    @GetMapping("/base/selectProductCategoryById/{rid}")
    public CommonRespDto selectProductCategoryById(@PathVariable Integer rid){
        return CommonRespDto.success(productCategoryBaseService.selectProductCategoryById(rid));
    }
    @GetMapping(value = "/insertProductCategory/")
    public RespBean insertProductCategoryByName( String productCategory){
        System.out.println(productCategory);
        ProductCategory category = new ProductCategory();
        category.setCategoryName(productCategory);
        category.setCreateTime(new Date());
        if(productCategoryBaseService.insertProductCategory(category) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @PostMapping("/base/insertProductCategory")
    public RespBean insertProductCategory(@RequestBody ProductCategory productCategory){
        if(productCategoryBaseService.insertProductCategory(productCategory) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteProductCategory/{rid}")
    public RespBean deleteProductCategoryById(@PathVariable Integer rid){
        if(productCategoryBaseService.deleteProductCategoryById(rid) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateProductCategory")
    public RespBean updateProductCategory(@RequestBody ProductCategory productCategory){

        if(productCategoryBaseService.updateProductCategory(productCategory) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
